'use strict';

const Controller = require('egg').Controller;

class WxController extends Controller {
  // 获取openid 和 session——key
  async index() {
    const js_code = this.ctx.params.code;
    const appid = 'wx42c160d0e3c8e072';
    const secret = '15bae952c01e572b9ba47f8fdd68508f';
    const res = await this.ctx.curl('https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + js_code + '&grant_type=authorization_code');
    this.ctx.body = res.data.toString();
  }
}

module.exports = WxController;
